import GlobalVue from '@concordcrm/vite-plugin-global-vue'
import vue from '@vitejs/plugin-vue'
import laravel from 'laravel-vite-plugin'
import Unfonts from 'unplugin-fonts/vite'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import { defineConfig } from 'vite'
import path from 'path'

const moduleAliasRegex = /@\/([a-zA-Z]+)\/(.*)/

export default defineConfig({
  resolve: {
    alias: [
      { find: moduleAliasRegex, replacement: '/modules/$1/resources/js/$2' },
    ],
  },
  plugins: [
    // eslint-disable-next-line prettier/prettier
    laravel([
      'resources/js/app.js',
      'resources/css/contentbuilder/theme.css'
    ]),
    createSvgIconsPlugin({
      iconDirs: [path.resolve(process.cwd(), '/resources/icons')],
      symbolId: '[dir]:[name]',
    }),
    Unfonts({
      custom: {
        families: [
          {
            name: 'Dancing Script',
            local: 'Dancing Script',
            src: './public/fonts/DancingScript-Regular.ttf',
          },
        ],
      },
    }),
    GlobalVue('3.4.15'),
    vue({
      template: {
        transformAssetUrls: {
          // The Vue plugin will re-write asset URLs, when referenced
          // in Single File Components, to point to the Laravel web
          // server. Setting this to `null` allows the Laravel plugin
          // to instead re-write asset URLs to point to the Vite
          // server instead.
          base: null,
          // The Vue plugin will parse absolute URLs and treat them
          // as absolute paths to files on disk. Setting this to
          // `false` will leave absolute URLs un-touched so they can
          // reference assets in the public directory as expected.
          includeAbsolute: false,
        },
      },
    }),
  ],
  server: {
    hmr: {
      host: 'localhost',
    },
  },
})
